package main

import (
	"flag"
	"fmt"
	"github.com/zeromicro/go-zero/core/conf"
	"github.com/zeromicro/go-zero/rest"
	"net/http"
	"property_api/internal/config"
	"property_api/internal/handler"
	"property_api/internal/svc"
)

var configFile = flag.String("f", "etc/property-api.yaml", "the config file")

func main() {
	flag.Parse()

	var c config.Config
	conf.MustLoad(*configFile, &c)
	//server := rest.MustNewServer(c.RestConf, rest.WithCors("*"))
	server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(
		func(header http.Header) {
			header.Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE")
			header.Set("Access-Control-Allow-0rigin", "*")
			//充许自定义头部rsa Access-Control-Request-Headers:rsa
			header.Set("Access-Control-Allow-Headers", "rsa,authorization,content-type")
		},
		func(Writer http.ResponseWriter) {},
	)) //解决跨域
	defer server.Stop()

	ctx := svc.NewServiceContext(c)
	handler.RegisterHandlers(server, ctx)

	fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
	server.Start()
}
